<?php
namespace app\admin\controller;

use think\Session;

class Index extends Base
{
    public function index()
    {
      print_r(Session::get('logininfo'));

        //今日统计

        $days=model('Business')->whereTime('create_time', 'd')->select();
        $daycount=count($days);
        $days['count']=$daycount;
          //已办结数
        $dayse=model('Business')->whereTime('update_time', 'd')->where('status',5)->select();
        $daycounte=count($dayse);
        $days['counte']=$daycounte;

        $this->assign('days',$days);


        //本周统计
        $weeks=model('Business')->whereTime('create_time', 'week')->select();
        $weekcount=count($weeks);
        $weeks['count']=$weekcount;
          //已办结数
        $weekse=model('Business')->whereTime('update_time', 'w')->where('status',5)->select();
        $weekcounte=count($weekse);
        $weeks['counte']=$weekcounte;
        $this->assign('weeks',$weeks);

        //本月统计
        $month=model('Business')->whereTime('create_time', 'm')->select();
        $monthcount=count($month);
        $month['count']=$monthcount;
          //已办结数
        $monthe=model('Business')->whereTime('update_time', 'm')->where('status',5)->select();
        $monthcounte=count($monthe);
        $month['counte']=$monthcounte;
        $this->assign('month',$month);

        //本年统计
        $years=model('Business')->whereTime('create_time', 'y')->select();
        $yearscount=count($years);
        $years['count']=$yearscount;
          //已办结数
        $yearse=model('Business')->whereTime('update_time', 'y')->where('status',5)->select();
        $yearscounte=count($yearse);
        $years['counte']=$yearscounte;
        $this->assign('years',$years);


        //待办事项
        $field = [
            'bus.id'=>'bus_id',
            'bus.no'=>'bus_no',
            'bus.name'=>'bus_name',
            'bus.tel'=>'bus_tel',
            'bus.cate_id'=>'bus_cate_id',
            'bus.area_id'=>'bus_area_id',
            'bus.content'=>'bus_content',
            'bus.status'=>'bus_status',
            'bus.create_time'=>'bus_create_time',
            'bus.update_time'=>'bus_update_time',
            'cate.id'=>'cate_id',
            'cate.name'=>'cate_name',
            'area.id'=>'area_id',
            'area.name'=>'area_name'
        ];
        if(Session::get('logininfo')['group_id']==2){
            $where=[
                'status'=>8,
            ];
        }
        else{
            if(Session::get('logininfo')['group_id']==13){
                $where=[
                    'status'=>1,
                    'pstatus'=>0,
                    'area_id'=>Session::get('logininfo')['area_id'],
                ];

            }
            else{
                $where=[
                    'status'=>Session::get('logininfo')['position_level'],
                ];
            }
            
        }

        $list = db('business')
            ->alias('bus')
            ->field($field)
            ->join('area area','bus.area_id = area.id')
            ->join('category cate',' bus.cate_id = cate.id')
            ->where($where)
            ->order("bus.id DESC")
            ->paginate(15);
        $this->assign('list',$list);

        return view();
        return view();
    }


}
